struct SemaphoreImpl_tag;

#ifndef __ROSA_SEMINT__
#define __ROSA_SEMINT__

#include <stdbool.h>
#include "kernel/rosa_task.h"

typedef enum {
	TYPE_BINARY = 0xCC,
	TYPE_IPCP = 0xCD,
	} SemaphoreType;

/// A struct for both semaphore types.
typedef struct SemaphoreImpl_tag {
	SemaphoreType type;							// Binary or IPCP type
	struct tcb_record_t *blockListHead;			// Linked list of tasks that are blocked on this semaphore.
	struct SemaphoreImpl_tag *next;				// Linked list of all semaphores.
	struct SemaphoreImpl_tag *lockListNext;		// Linked list of IPCP semaphores locked by a certain task
	unsigned int ceiling;						// Priority ceiling. Only valid for IPCP semaphores.
	bool semaphoreIsSignalled;					// Semaphore status. Whether the semaphore is available or not.
	} SemaphoreImpl;

/// A linked list of all semaphores
extern SemaphoreImpl *semaphoreListHead;

/// Times out the semaphore operation that the specified task is performing
/// The task is woken up and placed in the ready queue
void timeoutSemaphoreOperation(struct tcb_record_t *task);

/// Returns true if the task has locked any IPCP semaphore
bool taskHasLockedIPCPsemaphore(struct tcb_record_t *task);

#endif // __ROSA_SEMINT__